home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / Berkeley DB 1.8.5a / include / db.h next >
Text File  |  1995-10-08  |  9KB  |  290 lines

  1. /*-
  2.  * Copyright (c) 1990, 1993, 1994
  3.  *    The Regents of the University of California.  All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  *
  33.  *    @(#)db.h    8.7 (Berkeley) 6/16/94
  34.  */
  35.  
  36. #ifndef _DB_H_
  37. #define    _DB_H_
  38.  
  39. #include <sys/types.h>
  40. #include <sys/cdefs.h>
  41. #include <sys/errno.h>
  42.  
  43. #include <limits.h>
  44.  
  45. #ifdef __DBINTERFACE_PRIVATE
  46. #ifdef macintosh
  47. #define DB_open(file, flags, mode)     (open)((file), (flags))
  48. #define DB_read(fd, buf, count)        (read)((fd), (char *)(buf), (count))
  49. #define DB_write(fd, buf, count)    (write)((fd), (char *)(buf), (count))
  50.  
  51. #define NO_POSIX_SIGNALS 1
  52. #else
  53. #define DB_open    open
  54. #define    DB_read    read
  55. #endif
  56.  
  57. #ifndef BYTE_ORDER
  58. #define    LITTLE_ENDIAN    1234        /* LSB first: i386, vax */
  59. #define    BIG_ENDIAN    4321        /* MSB first: 68000, ibm, net */
  60. #define    BYTE_ORDER    BIG_ENDIAN    /* Set for your system. */
  61. #endif
  62.  
  63. typedef    int        ssize_t;    /* POSIX names. */
  64. typedef unsigned int    sigset_t;
  65.  
  66. #include <compat.h>
  67.  
  68. #endif
  69.  
  70. #ifdef __MWERKS__
  71. #define macintosh 1
  72. #endif
  73.  
  74. #ifdef macintosh
  75. #ifndef __signed
  76. #define __signed signed
  77. #endif
  78. #include <ConditionalMacros.h>
  79.  
  80. #ifndef PRAGMA_ALIGN_SUPPORTED
  81. #error Apple had some fun with the conditional macros again
  82. #endif
  83. #endif
  84.  
  85. #define    RET_ERROR    -1        /* Return values. */
  86. #define    RET_SUCCESS     0
  87. #define    RET_SPECIAL     1
  88.  
  89. #ifndef    __BIT_TYPES_DEFINED__
  90. #define    __BIT_TYPES_DEFINED__
  91. typedef    __signed char           int8_t;
  92. typedef    unsigned char         u_int8_t;
  93. typedef    short              int16_t;
  94. typedef    unsigned short        u_int16_t;
  95. typedef    int              int32_t;
  96. typedef    unsigned int        u_int32_t;
  97. #ifdef WE_DONT_NEED_QUADS
  98. typedef    long long          int64_t;
  99. typedef    unsigned long long    u_int64_t;
  100. #endif
  101. #endif
  102.  
  103. #define    MAX_PAGE_NUMBER    0xffffffff    /* >= # of pages in a file */
  104. typedef u_int32_t    pgno_t;
  105. #define    MAX_PAGE_OFFSET    65535        /* >= # of bytes in a page */
  106. typedef u_int16_t    indx_t;
  107. #define    MAX_REC_NUMBER    0xffffffff    /* >= # of records in a tree */
  108. typedef u_int32_t    recno_t;
  109.  
  110. /* Key/data structure -- a Data-Base Thang. */
  111. typedef struct {
  112.     void    *data;            /* data */
  113.     size_t     size;            /* data length */
  114. } DBT;
  115.  
  116. /* Routine flags. */
  117. #define    R_CURSOR    1        /* del, put, seq */
  118. #define    __R_UNUSED    2        /* UNUSED */
  119. #define    R_FIRST        3        /* seq */
  120. #define    R_IAFTER    4        /* put (RECNO) */
  121. #define    R_IBEFORE    5        /* put (RECNO) */
  122. #define    R_LAST        6        /* seq (BTREE, RECNO) */
  123. #define    R_NEXT        7        /* seq */
  124. #define    R_NOOVERWRITE    8        /* put */
  125. #define    R_PREV        9        /* seq (BTREE, RECNO) */
  126. #define    R_SETCURSOR    10        /* put (RECNO) */
  127. #define    R_RECNOSYNC    11        /* sync (RECNO) */
  128.  
  129. typedef enum { DB_BTREE, DB_HASH, DB_RECNO } DBTYPE;
  130.  
  131. /*
  132.  * !!!
  133.  * The following flags are included in the dbopen(3) call as part of the
  134.  * open(2) flags.  In order to avoid conflicts with the open flags, start
  135.  * at the top of the 16 or 32-bit number space and work our way down.  If
  136.  * the open flags were significantly expanded in the future, it could be
  137.  * a problem.  Wish I'd left another flags word in the dbopen call.
  138.  *
  139.  * !!!
  140.  * None of this stuff is implemented yet.  The only reason that it's here
  141.  * is so that the access methods can skip copying the key/data pair when
  142.  * the DB_LOCK flag isn't set.
  143.  */
  144. #if UINT_MAX > 65535
  145. #define    DB_LOCK        0x20000000    /* Do locking. */
  146. #define    DB_SHMEM    0x40000000    /* Use shared memory. */
  147. #define    DB_TXN        0x80000000    /* Do transactions. */
  148. #else
  149. #define    DB_LOCK            0x2000    /* Do locking. */
  150. #define    DB_SHMEM        0x4000    /* Use shared memory. */
  151. #define    DB_TXN            0x8000    /* Do transactions. */
  152. #endif
  153.  
  154. /* Access method description structure. */
  155. #if PRAGMA_ALIGN_SUPPORTED
  156. #pragma options align=power
  157. #endif
  158.  
  159. typedef struct __db {
  160.     DBTYPE type;            /* Underlying db type. */
  161.     int (*close)    __P((struct __db *));
  162.     int (*del)    __P((const struct __db *, const DBT *, u_int));
  163.     int (*get)    __P((const struct __db *, const DBT *, DBT *, u_int));
  164.     int (*put)    __P((const struct __db *, DBT *, const DBT *, u_int));
  165.     int (*seq)    __P((const struct __db *, DBT *, DBT *, u_int));
  166.     int (*sync)    __P((const struct __db *, u_int));
  167.     void *internal;            /* Access method private. */
  168.     int (*fd)    __P((const struct __db *));
  169. } DB;
  170.  
  171. #if PRAGMA_ALIGN_SUPPORTED
  172. #pragma options align=reset
  173. #endif
  174.  
  175. #define    BTREEMAGIC    0x053162
  176. #define    BTREEVERSION    3
  177.  
  178. /* Structure used to pass parameters to the btree routines. */
  179. typedef struct {
  180. #define    R_DUP        0x01    /* duplicate keys */
  181.     u_long    flags;
  182.     u_int    cachesize;    /* bytes to cache */
  183.     int    maxkeypage;    /* maximum keys per page */
  184.     int    minkeypage;    /* minimum keys per page */
  185.     u_int    psize;        /* page size */
  186.     int    (*compare)    /* comparison function */
  187.         __P((const DBT *, const DBT *));
  188.     size_t    (*prefix)    /* prefix function */
  189.         __P((const DBT *, const DBT *));
  190.     int    lorder;        /* byte order */
  191. } BTREEINFO;
  192.  
  193. #define    HASHMAGIC    0x061561
  194. #define    HASHVERSION    2
  195.  
  196. /* Structure used to pass parameters to the hashing routines. */
  197. typedef struct {
  198.     u_int    bsize;        /* bucket size */
  199.     u_int    ffactor;    /* fill factor */
  200.     u_int    nelem;        /* number of elements */
  201.     u_int    cachesize;    /* bytes to cache */
  202.     u_int32_t        /* hash function */
  203.         (*hash) __P((const void *, size_t));
  204.     int    lorder;        /* byte order */
  205. } HASHINFO;
  206.  
  207. #if PRAGMA_ALIGN_SUPPORTED
  208. #pragma options align=power
  209. #endif
  210.  
  211. /* Structure used to pass parameters to the record routines. */
  212. typedef struct {
  213. #define    R_FIXEDLEN    0x01    /* fixed-length records */
  214. #define    R_NOKEY        0x02    /* key not required */
  215. #define    R_SNAPSHOT    0x04    /* snapshot the input */
  216.     u_long    flags;
  217.     u_int    cachesize;    /* bytes to cache */
  218.     u_int    psize;        /* page size */
  219.     int    lorder;        /* byte order */
  220.     size_t    reclen;        /* record length (fixed-length records) */
  221.     u_char    bval;        /* delimiting byte (variable-length records */
  222.     char    *bfname;    /* btree file name */ 
  223. } RECNOINFO;
  224.  
  225. #if PRAGMA_ALIGN_SUPPORTED
  226. #pragma options align=reset
  227. #endif
  228.  
  229. #ifdef __DBINTERFACE_PRIVATE
  230. /*
  231.  * Little endian <==> big endian 32-bit swap macros.
  232.  *    M_32_SWAP    swap a memory location
  233.  *    P_32_SWAP    swap a referenced memory location
  234.  *    P_32_COPY    swap from one location to another
  235.  */
  236. #define    M_32_SWAP(a) {                            \
  237.     u_int32_t _tmp = a;                        \
  238.     ((char *)&a)[0] = ((char *)&_tmp)[3];                \
  239.     ((char *)&a)[1] = ((char *)&_tmp)[2];                \
  240.     ((char *)&a)[2] = ((char *)&_tmp)[1];                \
  241.     ((char *)&a)[3] = ((char *)&_tmp)[0];                \
  242. }
  243. #define    P_32_SWAP(a) {                            \
  244.     u_int32_t _tmp = *(u_int32_t *)a;                \
  245.     ((char *)a)[0] = ((char *)&_tmp)[3];                \
  246.     ((char *)a)[1] = ((char *)&_tmp)[2];                \
  247.     ((char *)a)[2] = ((char *)&_tmp)[1];                \
  248.     ((char *)a)[3] = ((char *)&_tmp)[0];                \
  249. }
  250. #define    P_32_COPY(a, b) {                        \
  251.     ((char *)&(b))[0] = ((char *)&(a))[3];                \
  252.     ((char *)&(b))[1] = ((char *)&(a))[2];                \
  253.     ((char *)&(b))[2] = ((char *)&(a))[1];                \
  254.     ((char *)&(b))[3] = ((char *)&(a))[0];                \
  255. }
  256.  
  257. /*
  258.  * Little endian <==> big endian 16-bit swap macros.
  259.  *    M_16_SWAP    swap a memory location
  260.  *    P_16_SWAP    swap a referenced memory location
  261.  *    P_16_COPY    swap from one location to another
  262.  */
  263. #define    M_16_SWAP(a) {                            \
  264.     u_int16_t _tmp = a;                        \
  265.     ((char *)&a)[0] = ((char *)&_tmp)[1];                \
  266.     ((char *)&a)[1] = ((char *)&_tmp)[0];                \
  267. }
  268. #define    P_16_SWAP(a) {                            \
  269.     u_int16_t _tmp = *(u_int16_t *)a;                \
  270.     ((char *)a)[0] = ((char *)&_tmp)[1];                \
  271.     ((char *)a)[1] = ((char *)&_tmp)[0];                \
  272. }
  273. #define    P_16_COPY(a, b) {                        \
  274.     ((char *)&(b))[0] = ((char *)&(a))[1];                \
  275.     ((char *)&(b))[1] = ((char *)&(a))[0];                \
  276. }
  277. #endif
  278.  
  279. __BEGIN_DECLS
  280. DB *dbopen __P((const char *, int, int, DBTYPE, const void *));
  281.  
  282. #ifdef __DBINTERFACE_PRIVATE
  283. DB    *__bt_open __P((const char *, int, int, const BTREEINFO *, int));
  284. DB    *__hash_open __P((const char *, int, int, const HASHINFO *, int));
  285. DB    *__rec_open __P((const char *, int, int, const RECNOINFO *, int));
  286. void     __dbpanic __P((DB *dbp));
  287. #endif
  288. __END_DECLS
  289. #endif /* !_DB_H_ */
  290.